package cloud.keveri.base;

import lombok.Data;

import static cloud.keveri.base.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;

/**
 * 系统异常
 * <p>
 * 作者：沈自在
 **/
@Data
public class KeveriException extends RuntimeException {

    /**
     * 业务错误码
     */
    private Integer code;
    /**
     * 错误提示
     */
    private String message;

    private void defaultError(){
        this.code = INTERNAL_SERVER_ERROR.getCode();
        this.message = INTERNAL_SERVER_ERROR.getMessage();
    }

    private KeveriException() {
    }

    public KeveriException(final String message) {
        super(message);
        defaultError();
    }

    public KeveriException(final Throwable e) {
        super(e);
        defaultError();
    }

    public KeveriException(ErrorCode error) {
        this.code = error.getCode();
        this.message = error.getMessage();
    }

    /**
     *
     */
    public KeveriException setCode(Integer code){
        this.code = code;
        return this;
    }

    /**
     *
     */
    public KeveriException setMessage(String message){
        this.message = message;
        return this;
    }
    /**
     *
     */
    @Override
    public String getMessage() {
        return message;
    }
}
